package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

@Getter@Setter
public class Region extends BaseDomain{
    public final static int STATE_NORMAL=0;
    public final static int STATE_DISABLE=-1;
    public final static int STATE_COMMENT=1;
    private String name;//名称

    private Integer state=STATE_NORMAL;//状态

    private Region parent;//上级地区

    public String getStateName(){
        String msg = "设为推荐";
        if (state==STATE_COMMENT) {
            msg = "取消推荐";
        }else if (state==STATE_NORMAL) {
            msg = "设为推荐";
        }
        return  msg;
    }

    public String getJson(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("name",name);
        map.put("state",state);
        return JSONUtil.toJSONString(map);
    }
    //把当前地区对象转为Map的集合,用来匹配treeMap
    public Map toTreeMap(){
        Map map = new HashMap();
        map.put("text",name);
        map.put("id",id);
        map.put("lazyLoad",true);
        if (state==STATE_COMMENT) {
            map.put("tags",new String[]{"推荐"});
        }
        return map;
    }




}